package com.hxkcloud.patient.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.beans.MessageBean;
import com.hxkcloud.patient.viewholders.MsgMainViewholder;

import java.util.List;

/**
 * Created by william_sun on 2016-07-18.
 * Description:
 */
public class MsgMainAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<MessageBean> datas;
    private Context mContext;
    private int screenWidth;
    private LayoutInflater mInflater;

    public MsgMainAdapter(Context mContext, int screenWidth, List<MessageBean> datas) {
        this.mContext = mContext;
        this.screenWidth = screenWidth;
        this.datas = datas;
        mInflater = LayoutInflater.from(mContext);
    }

    public void setData(List<MessageBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.adapter_messagemain, null);
        MsgMainViewholder holder = new MsgMainViewholder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MsgMainViewholder mHolder = (MsgMainViewholder) holder;
        MessageBean bean = datas.get(position);

        LinearLayout.LayoutParams lp_rl = new LinearLayout.LayoutParams(screenWidth / 8, screenWidth / 8);
        mHolder.rl_head.setLayoutParams(lp_rl);
        mHolder.tv_msg.setText(bean.getLastestMessage());
        mHolder.tv_date.setText(bean.getDate());
        mHolder.tv_name.setText(bean.getName());
        mHolder.tv_num.setText(bean.getNum());

    }

    @Override
    public int getItemCount() {
        return datas.size();
    }
}
